/**
 * Created by jianglinjie on Tue Oct 10 2017
 * @flow
 */
'use strict';
import ConfigService from '../config';
import type { UpdateUserParam, UpdateUserResult, GetUserParam, GetUserResult } from '../../serviceTypes';
import { FetchClient, JSONRequest, HttpMethod, GetRequest } from '../../network';

const USER_PATH = '/users';

class UserProfileService {
  async update(param: UpdateUserParam): Promise<UpdateUserResult> {
    let { uid, ...json } = param;
    let request = new JSONRequest(
      ConfigService.apiBaseHost + USER_PATH + `/${uid}`, 
      {}, 
      json,
      HttpMethod.PATCH,
    );

    let body = await FetchClient.start(request);
    return body.data;
  }

  async getUser(param: GetUserParam): Promise<GetUserResult> {
    let request = new GetRequest(
      ConfigService.apiBaseHost + USER_PATH + `/${param.uid}`
    );

    let body = await FetchClient.start(request);
    return body.data;    
  }
}

export default new UserProfileService();
